package com.cheboohui.iqs.spider.pingan.price;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.alibaba.fastjson.JSONObject;

/***
 * 保险时间判断
 * 
 * @author xielonghai
 *
 */
public class TimeDeal {

	/**** 获取交强险的保险开始时间 *****/
	public static String getTime_tra(JSONObject response) {
		try {
			JSONObject obj = response.getJSONObject("c51CaculateResult").getJSONObject("c51ResultDTO")
					.getJSONObject("thirdVehicleReinsure");
			String time = obj.getString("dateExpire");
			String msg = obj.getString("licensePlateNo");// 渝B67H90”的保单发生重复投保，与其重复投保的其它公司的保单信息如下：车架号
															// LPAA2FAC2E2012699
			if (null != msg && msg.indexOf("重复投保") >= 0 && null == time) {
				return "tra";
			}
			return time;
		} catch (Exception e) {
			return "";
		}
	}

	/** 获取保险开始时间 */
	public static String getTime(JSONObject response) {
		String time = "";
		try {
			time = response.getJSONObject("applyQueryResult").getJSONObject("circInfoDTO")
					.getJSONArray("thirdVehicleReinsureList").getJSONObject(0).getString("dateExpire");

			return time;
		} catch (Exception e) {
			return "";
		}
	}

	/** 判断上年保险结束时间相隔今天是否大于90天 */
	public static int timeInterval(String time) {
		try {
			Date end = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(time);
			Date now = new Date();
			int days = (int) ((end.getTime() - now.getTime()) / 86400000);
			return days;
		} catch (Exception e) {
			return -1;
		}
	}
}
